#!/bin/bash
# centos 一键安装jdk1.8

cd ~
echo "选择安装版本："；
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
echo ">>>1. 部分安装功能不缺（一百兆左右）>>>";
echo ">>>2. 全部安装 （1G左右）>>>>>>>>>>>>>>";
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
read CHIOCE;
if [ $# == 0 ]; then 
	echo "==> 默认选择 ==> “1”"；
	yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
else
	if [[ $CHIOCE == '1' ]]; then
		echo "==> 将开始下载部分版本";
		yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
	elif [[ $CHINCE == '2' ]]; then
		echo "==> 将开始下载完整版本";
		yum install java-1.8.0-openjdk* -y
	else
		echo "==> 默认选择 ==> “1”"；
	yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
		#statements
	fi
fi

if [ $? == 0 ]; then
	echo "==> 设置环境变量！";
	echo "JAVA_HOME=/usr/lib/jvm/java" >> /etc/profile
	echo "PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
	echo "CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
	echo "export JAVA_HOME CLASSPATH PATH" >> /etc/profile
else
	echo "==> 执行失败！";
	eixt;
fi

echo "==> 验证："
java -version
javac -version
if [ $? -eq 0 ]; then
	echo "==> 安装成功！";
else
	echo "==> 安装失败！";
fi
